package com.zzy.action;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zzy.model.Product;
import com.zzy.service.ProductService;

@Controller


public class ProductAdd {

	
	@Autowired
	ProductService productService;
	
	
	@RequestMapping("/addProduct")
	 public String login() {
	    
	      return "addProduct";
	}
	
	
	@RequestMapping("/addAction")
	
	public  String productAction(HttpServletRequest request, HttpServletResponse response,Model model){
		 String commonName=request.getParameter("commonName");
		 String name=request.getParameter("name");
		 String vender=request.getParameter("vender");
		 String license=request.getParameter("license");
		 String function=request.getParameter("function");
		 String taboo=request.getParameter("taboo");
		 String showPrice=request.getParameter("showPrice");
		 String status=request.getParameter("status");
		 //添加人信息就是当前登录用户信息,  一般用户登录把信息放在session里面,这里可以直接从session获取添加人信息
		 String addUserId=request.getParameter("addUserId");
		 String addUserRealname=request.getParameter("addUserRealname");
		 String addTime=request.getParameter("addTime");
		 
		 
		 
		 //#{id},#{commonName},#{name},#{vender},#{license},#{function},#{taboo},#{showPrice}
		 //保证这几个值不为空
		 
		 Product  product=new  Product();
		 product.setAddTime(new Date());   //添加时间为当前时间
		 product.setAddUserId(addUserId);
		 product.setAddUserRealname(addUserRealname);
	     product.setCommonName(commonName);
		 product.setFunction(function);
		 product.setLicense(license);
		 product.setName(name);
		 product.setShowPrice(showPrice);
		 product.setStatus(status);
		 product.setTaboo(taboo);
		 product.setVender(vender);
		 product.setId(System.currentTimeMillis());
		 productService.add(product);
	
		  
		
		String base=request.getContextPath();
		model.addAttribute("base", base);
		
	     
		
		return "list";
		}
}
